package com.honour.controller.interfaced;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.honour.service.interfaced.HomePageInManager;
import com.honour.service.interfaced.impl.AdvertisementInService;
import com.honour.service.interfaced.impl.MagazineInService;
import com.honour.service.interfaced.impl.MenuInService;
import com.system.controller.base.BaseController;
import com.system.util.AppUtil;
import com.system.util.PageData;
import com.system.util.Tools;

/**
 @Function
 @Author zhaozhenhua
 @Date   2018年1月12日
*/
@Controller
@RequestMapping(value="/appmagazinein")
public class MagazineInController extends BaseController{
	
	/**
	 * 首页相关方法
	 */
	@Resource(name="menuInService")
	private MenuInService menuInService;
	
	@Resource(name="advertisementInService")
	private AdvertisementInService advertisementInService;
	
	@Resource(name="homeinService")
	private HomePageInManager homeinService;
	
	@Resource(name="magazineInService")
	private MagazineInService magazineInService;
	
	

	/**
	 * 通过ID获取其子一级菜单
	 * @Author 于泓磊
	 * @date   2018年1月12日
	 * @return
	 */
	@RequestMapping(value="/getlistsubmenu")
	@ResponseBody
	public Object getListSubMenu(){
		logBefore(logger, "通过ID获取其子一级菜单");
		Map<String,Object> map = new HashMap<String,Object>();
		PageData pd = new PageData();
		pd = this.getPageData();
		String result = "00";
		try{
			if(Tools.checkKey("LISTSUBMENU", pd.getString("FKEY"))){	//检验请求key值是否合法
				pd.put("PARENT_ID", "212");        //212为荣耀杂志的id
				List<PageData> list = menuInService.getListSubMenuByParentId(pd);
				pd.put("RELATED_ID", "212");
				List<PageData> ads = advertisementInService.getAdByPosition(pd);
				List<PageData> magazines = magazineInService.getMagazinesByHome(pd);
				if (list.size()!=0) {
					map.put("pd", list);
					map.put("ads", ads);
					map.put("magazines", magazines);
				}
				//返回01为查询成功并返回,02为此私人订制暂无详情
				result = (0== list.size()) ?  "02" :  "01";
			}else{
				result = "05";
			}
		}catch (Exception e){
			logger.error(e.toString(), e);
		}finally{
			map.put("result", result);
			logAfter(logger);
		}
		return AppUtil.returnObject(new PageData(), map);
	}
	
}
